﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    
    /// <summary>
    /// member 的摘要说明
    /// </summary>
    public class member : IHttpHandler, IRequiresSessionState
    {
        public string msg = "";

        public void ProcessRequest(HttpContext context)
        {
            //取得处事类型
            string action = DTRequest.GetQueryString("action");

            switch (action)
            {
                case "gongying_list": //提交评论
                    gongying_list(context);
                    break;
                case "my_xinxi_list": //提交评论
                    my_xinxi_list(context);
                    break;
                case "gongying_delete": //删除供应信息
                    gongying_delete(context);
                    break;
                case "qiugou_list": //我发布的求购信息
                    qiugou_list(context);
                    break;
                case "qiugou_delete": //删除供应信息
                    qiugou_delete(context);
                    break;
                case "product_list": //提交评论
                    product_list(context);
                    break;
                case "product_delete": //删除供应信息
                    product_delete(context);
                    break;
                case "product_toTop": //删除供应信息
                    product_toTop(context);
                    break;
                case "wuliu_list": //我发布的物流信息
                    wuliu_list(context);
                    break;
                case "wuliu_delete": //删除物流信息
                    wuliu_delete(context);
                    break;
                case "xxs_list": //我发布的物流信息
                    xxs_list(context);
                    break;
                case "xxs_delete": //删除物流信息
                    xxs_delete(context);
                    break;
                case "zan_add": //添加赞
                    zan_add(context);
                    break;
                case "job_list": //我发布的招聘信息
                    job_list(context);
                    break;
                case "job_delete": //删除招聘信息
                    job_delete(context);
                    break;
                case "zhoubian_list": //我发布的招聘信息
                    zhoubian_list(context);
                    break;
                case "zhoubian_delete": //删除招聘信息
                    zhoubian_delete(context);
                    break;
                case "user_avatar_save": //确认裁剪用户头像
                    user_avatar_save(context);
                    break;
                case "get_userinfo": //获取用户信息
                    get_userinfo(context);
                    break;
                case "get_user_info": //根据用户ID获取用户信息
                    get_user_info(context);
                    break;
                case "get_company_info": //根据用户密码获取公司信息
                    get_company_info(context);
                    break;
                case "collect_list": //我的收藏
                    collect_list(context);
                    break;
                case "collect_add": //添加收藏
                    collect_add(context);
                    break;
                case "collect_delete": //删除收藏
                    collect_delete(context);
                    break;
                case "company_add": //新增加企业店铺
                    company_add(context);
                    break;
                case "company_edit": //修改加企业店铺
                    company_edit(context);
                    break;
                case "company_edit_zuobiao": //修改加企业店铺
                    company_edit_zuobiao(context);
                    break;
                case "company_about_edit": //修改加企业店铺
                    company_about_edit(context);
                    break;
                case "company_logo_edit": //修改加企业店铺
                    company_logo_edit(context);
                    break;
                case "get_product_category": //获取产品分类
                    get_product_category(context);
                    break;
                case "product_add": //获取产品分类
                    product_add(context);
                    break;
                case "xiangce_add": //获取产品分类
                    xiangce_add(context);
                    break;
                case "xiangce_delete": //删除供应信息
                    xiangce_delete(context);
                    break;
                case "xiangce_toTop": //删除供应信息
                    xiangce_toTop(context);
                    break;
                case "banner_add": //添加店铺黄页 banner  三张
                    banner_add(context);
                    break;
                case "banner_delete": //删除 店铺黄页 banner  三张
                    banner_delete(context);
                    break;
                case "get_userGroups": //Demon 添加 获取会员级别组
                    get_userGroups(context);
                    break;

                case "get_xinxicomment_at": //Demon 添加 获取@我的消息
                    get_xinxicomment_at(context);
                    break;

            }
        }

        #region 我发布的供应信息=============================
        private void gongying_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.gongying bll = new BLL.gongying();
            DataSet ds = bll.GetList(page_size, page_index, "user_id=" + userModel.id, "id desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"size\":\"" + dr["size_long"] + "×" + dr["size_wide"] + "×" + dr["size_height"] + "\"");
                    strTxt.Append(",\"img_url\":\"http:\\/\\/www.shicaiquanzi.com" + dr["img_url"] + "\"");
                    strTxt.Append(",\"content\":\"" + Microsoft.JScript.GlobalObject.escape(dr["content"].ToString().Replace("<p>", "").Replace("</p>", "")) + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr["add_time"])) + "\"");
                    strTxt.Append(",\"market_price\":\"" + dr["price"] + "/" + dr["unit"] + "\"");
                    strTxt.Append(",\"mobile\":\"" + dr["mobile"] + "\"");
                    strTxt.Append(",\"hits\":" + dr["hits"]);
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 我发布的供应信息=============================
        private void my_xinxi_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.xinxi bll = new BLL.xinxi();
            DataSet ds = bll.GetList(page_size, page_index, "user_id=" + userModel.id, "add_time desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    string remark = dr["content"].ToString();
                    if (remark.Length >= 40)
                    {
                        remark = remark.Substring(40);
                    }
                    strTxt.Append(",\"content\":\"" + Microsoft.JScript.GlobalObject.escape(remark.Replace("<p>", "").Replace("</p>", "")) + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr["add_time"])) + "\"");
                    strTxt.Append(",\"hits\":" + dr["hits"]);

                    #region  添加 获取未读信息评论的数量 Demon 20190420
                    // 添加 获取未读信息评论的数量 Demon 20190420
                    int xinxi_commentnum = new BLL.xinxi_comment().GetCommentsNumByxinxi_id(int.Parse(dr["id"].ToString()));
                    strTxt.Append(",\"xinxi_commentnum\":" + xinxi_commentnum);
                    #endregion


                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 删除供应信息=============================
        private void gongying_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.xinxi bll = new BLL.xinxi();
            Model.xinxi model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 我发布的求购信息=============================
        private void qiugou_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.qiugou bll = new BLL.qiugou();
            DataSet ds = bll.GetList(page_size, page_index, "user_id=" + userModel.id, "id desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"size\":\"" + dr["size_long"] + "×" + dr["size_wide"] + "×" + dr["size_height"] + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr["add_time"])) + "\"");
                    strTxt.Append(",\"mobile\":\"" + dr["mobile"] + "\"");
                    strTxt.Append(",\"hits\":" + dr["hits"]);
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 删除求购信息=============================
        private void qiugou_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.qiugou bll = new BLL.qiugou();
            Model.qiugou model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(2, article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 我发布的产品=============================
        private void product_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.product bll = new BLL.product();
            DataSet ds = bll.GetList(page_size, page_index, "user_id=" + userModel.id, "add_time desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"hits\":\"" + dr["hits"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 删除产品信息=============================
        private void product_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.product bll = new BLL.product();
            Model.product model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(3, article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 我发布的物流信息=============================
        private void wuliu_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.wuliu bll = new BLL.wuliu();
            DataSet ds = bll.GetList(page_size, page_index, "user_id=" + userModel.id, "id desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    int _typeid = Convert.ToInt32(dr["type_id"].ToString());
                    strTxt.Append(",\"type_id\":" + _typeid);
                    if (_typeid == 1)
                    {
                        strTxt.Append(",\"type_name\":\"求车\"");
                    }
                    else if (_typeid == 2)
                    {
                        strTxt.Append(",\"type_name\":\"求货\"");
                    }
                    strTxt.Append(",\"title\":\"" + dr["start_address"] + "->" + dr["end_address"] + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr["add_time"])) + "\"");
                    strTxt.Append(",\"mobile\":\"" + dr["mobile"] + "\"");
                    strTxt.Append(",\"hits\":\"" + dr["hits"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 删除物流信息=============================
        private void wuliu_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.wuliu bll = new BLL.wuliu();
            Model.wuliu model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 我发布的新鲜事=============================
        private void xxs_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.xinxianshi bll = new BLL.xinxianshi();
            DataSet ds = bll.GetList(page_size, page_index, "user_id=" + userModel.id, "id desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"remark\":\"" + dr["remark"] + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr["add_time"])) + "\"");
                    strTxt.Append(",\"hits\":\"" + dr["hits"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 删除新鲜事=============================
        private void xxs_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.xinxianshi bll = new BLL.xinxianshi();
            Model.xinxianshi model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 添加赞=============================
        private void zan_add(HttpContext context)
        {
            //检查用户是否登录
            string user_name = DTRequest.GetFormString("txtUserName");
            string user_pwd = DTRequest.GetFormString("txtPassword");
            int _article_id = DTRequest.GetFormInt("article_id");

            if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"尚未登录，不能点赞！\"}");
                return;
            }
            Model.users userModel = new BLL.users().GetModel(user_name, user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"尚未登录，不能点赞！\"}");
                return;
            }

            BLL.zan bll = new BLL.zan();
            //先判断是否有收藏过
            if (bll.Exists(_article_id, userModel.id))
            {
                //context.Response.Write("{\"status\": 0, \"msg\": \"已经赞过了！\"}");
                bool result = bll.Delete(_article_id, userModel.id);
                if (result)
                {
                    context.Response.Write("{\"status\": 1, \"is_cancel\": 1, \"msg\": \"取消成功！\"}");
                    new BLL.xinxianshi().UpdateField(_article_id, "zan=zan-1");
                }
                return;
            }
            Model.zan model = new Model.zan();

            model.article_id = _article_id;
            model.add_time = DateTime.Now;
            model.user_id = userModel.id;

            if (bll.Add(model) > 0)
            {
                context.Response.Write("{\"status\": 1, \"is_cancel\": 0, \"msg\": \"点赞成功！\"}");
                new BLL.xinxianshi().UpdateField(_article_id, "zan=zan+1");
                return;
            }
            context.Response.Write("{\"status\": 0, \"msg\": \"系统发生错误！\"}");
            return;

        }
        #endregion

        #region 我发布的招聘信息=============================
        private void job_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.jobs bll = new BLL.jobs();
            DataSet ds = bll.GetList(page_size, page_index, "user_id=" + userModel.id, "id desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    int _typeid = Convert.ToInt32(dr["type_id"].ToString());
                    strTxt.Append(",\"type_id\":" + _typeid);
                    if (_typeid == 1)
                    {
                        strTxt.Append(",\"type_name\":\"招聘\"");
                    }
                    else if (_typeid == 2)
                    {
                        strTxt.Append(",\"type_name\":\"求职\"");
                    }
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr["add_time"])) + "\"");
                    strTxt.Append(",\"mobile\":\"" + dr["mobile"] + "\"");
                    strTxt.Append(",\"hits\":\"" + dr["hits"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 删除招聘信息=============================
        private void job_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.jobs bll = new BLL.jobs();
            Model.jobs model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 我发布的周边信息=============================
        private void zhoubian_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.zhoubian bll = new BLL.zhoubian();
            DataSet ds = bll.GetList(0, page_size, page_index, "user_id=" + userModel.id, "id desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"category_name\":\"" + new BLL.zhoubian_category().GetTitle(Convert.ToInt32(dr["type_id"])) + "\"");
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr["add_time"])) + "\"");
                    strTxt.Append(",\"mobile\":\"" + dr["mobile"] + "\"");
                    strTxt.Append(",\"hits\":\"" + dr["hits"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 删除周边信息=============================
        private void zhoubian_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.zhoubian bll = new BLL.zhoubian();
            Model.zhoubian model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(4, article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 确认裁剪用户头像OK=============================
        private void user_avatar_save(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            HttpPostedFile upFile = context.Request.Files["file"];
            string new_filename = FileSaveAvatar(context, upFile);

            //取得保存的新文件名
            UpLoad upFiles = new UpLoad();
            //删除原用户头像
            upFiles.DeleteFile(userModel.avatar);
            userModel.avatar = new_filename;
            //修改用户头像
            new BLL.users().UpdateField(userModel.id, "avatar='" + new_filename + "'");
            if (userModel.company_id > 0)
            {
                new BLL.company().UpdateField(userModel.company_id, "logo='" + new_filename + "'");
            }
            context.Response.Write("{\"status\": 1, \"msg\": \"头像上传成功！\", \"avatar\": \"" + userModel.avatar + "\"}");
            return;
        }
        #endregion

        #region 统一保存文件=============================
        /// <summary>
        /// 统一保存文件
        /// </summary>
        private string FileSave(HttpContext context, HttpPostedFile upFiles, bool isWater)
        {
            //获取文件信息
            string fileName = upFiles.FileName;
            byte[] byteData = FileHelper.ConvertStreamToByteBuffer(upFiles.InputStream); //获取文件流
            //开始上传
            string remsg = new UpLoad().FileSaveAs(byteData, fileName, true, isWater);
            Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(remsg);
            string status = dic["status"].ToString();
            string msg = dic["msg"].ToString();
            if (status == "0")
            {
                //showError(context, msg);
                return "";
            }
            string filePath = dic["thumb"].ToString(); //取得上传后的路径
            return filePath;
            //showSuccess(context, fileName, filePath); //输出成功提示
        }
        #endregion

        #region 统一保存文件=============================
        /// <summary>
        /// 统一保存文件
        /// </summary>
        private string FileSaveAvatar(HttpContext context, HttpPostedFile upFiles)
        {
            //获取文件信息
            string fileName = upFiles.FileName;
            byte[] byteData = FileHelper.ConvertStreamToByteBuffer(upFiles.InputStream); //获取文件流
            //开始上传
            string remsg = new UpLoad().FileSaveCustom(byteData, fileName, 200, 200);
            Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(remsg);
            string status = dic["status"].ToString();
            string msg = dic["msg"].ToString();
            if (status == "0")
            {
                //showError(context, msg);
                return "";
            }
            string filePath = dic["thumb"].ToString(); //取得上传后的路径
            return filePath;
            //showSuccess(context, fileName, filePath); //输出成功提示
        }
        #endregion

        #region 获取用户信息=============================
        private void get_userinfo(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");
            /// Demon 添加 20190226 手机系统类型  
            /// ios
            /// android       
            /// win             //Windows系统   
            /// wp              //Windows Phone系统
            string _systemType = DTRequest.GetString("systemType"); 
            BLL.company combll = new BLL.company();
            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();

            strTxt.Append("{");
            strTxt.Append("\"id\":" + userModel.id);
            strTxt.Append(",\"user_name\":\"" + userModel.user_name + "\"");
            strTxt.Append(",\"mobile\":\"" + userModel.mobile + "\"");
            if (string.IsNullOrEmpty(userModel.avatar))
            {
                strTxt.Append(",\"avatar\":\"../image/default_avatar.png\"");
            }
            else
            {
                //strTxt.Append(",\"avatar\":\"" + userModel.avatar + "\"");
                //http://pic.shicaiquanzi.com/upload/201810/25/thumb_201810251453378010.jpg

                if (userModel.avatar.Contains("shicaiquanzi"))
                {
                    if (userModel.avatar.Contains("http://")) { strTxt.Append(",\"avatar\":\"" + userModel.avatar + "\""); }
                    else { strTxt.Append(",\"avatar\":\"http://" + userModel.avatar + "\""); }

                }
                else
                {
                    strTxt.Append(",\"avatar\":\"http://pic.shicaiquanzi.com" + userModel.avatar + "\"");
                }
               
            }
            
            strTxt.Append(",\"amount\":\"" + userModel.amount.ToString() + "\"");
            strTxt.Append(",\"company_id\":" + userModel.company_id);
            if (userModel.company_id > 0)
            {
                string companyname = combll.GetTitle(userModel.company_id);
                if (companyname + "" != "" && companyname != "-") { strTxt.Append(",\"company_name\":\"" + combll.GetTitle(userModel.company_id) + "\""); }
                else { strTxt.Append(",\"company_name\":\"\""); }
                
                string logo = combll.GetLogo(userModel.company_id);
                if (logo + "" != "")
                {
                    if (logo.Contains("shicaiquanzi"))
                    {
                        if (logo.Contains("http://")) { strTxt.Append(",\"logo\":\"" + logo + "\""); }
                        else { strTxt.Append(",\"logo\":\"http://" + logo + "\""); }
                    }
                    else
                    {
                        strTxt.Append(",\"logo\":\"http://pic.shicaiquanzi.com" + logo + "\"");
                    }
                }
                else { strTxt.Append(",\"logo\":\"\""); }
            }
            else {
                strTxt.Append(",\"company_name\":\"\"");
                strTxt.Append(",\"logo\":\"\"");
            }
            ///Demon 添加 20190226 
            ///手机系统类型 决定升级功能是否显示  0 显示   1：不显示
            if (_systemType == "ios")
            {
                strTxt.Append(",\"group_isshow\":" + 1);
            }
            else { strTxt.Append(",\"group_isshow\":" + 0); }
            //Utils.WriteTextLog("group_isshow", "_systemType:" + _systemType + ",strTxt:" + strTxt , DateTime.Now);
            strTxt.Append(",\"group_id\":" + userModel.group_id);

            if (userModel.group_id > 1)
            {
                string group_name = new BLL.user_groups().GetTitle(userModel.group_id);
                strTxt.Append(",\"group_name\":\"已开通" + group_name + "\"");
            }
            else
            {
                strTxt.Append(",\"group_name\":\"尚未开通\"");
            }

            #region  添加 获取未读信息评论的数量 Demon 20190420
            // 添加 获取未读信息评论的数量 Demon 20190420
            BLL.xinxi_comment commbll = new BLL.xinxi_comment();
            int xinxi_comment_num = commbll.GetCommentsNumByUserID(userModel.id);
            strTxt.Append(",\"xinxi_comment_num\":" + xinxi_comment_num);
            #endregion
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 根据用户ID获取用户信息=============================
        private void get_user_info(HttpContext context)
        {
            int _user_id = DTRequest.GetQueryInt("user_id");
            int _cur_userid = DTRequest.GetFormInt("txtUserID", 0);
            if (_user_id == 0)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：该用户已隐藏个人信息！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_id);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：无法获取用户信息！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();

            strTxt.Append("{");
            strTxt.Append("\"id\":" + userModel.id);
            strTxt.Append(",\"user_name\":\"" + userModel.user_name + "\"");
            strTxt.Append(",\"mobile\":\"" + userModel.mobile + "\"");
            if (string.IsNullOrEmpty(userModel.avatar))
            {
                strTxt.Append(",\"avatar\":\"../image/default_avatar.png\"");
            }
            else
            {
                //if (userModel.avatar.Contains("shicaiquanzi"))
                //{
                //    strTxt.Append(",\"avatar\":\"http://" + userModel.avatar + "\"");
                //}
                //else
                //{
                //    strTxt.Append(",\"avatar\":\"http://www.shicaiquanzi.com" + userModel.avatar + "\"");
                //}
                if (userModel.avatar.Contains("shicaiquanzi"))
                {
                    if (userModel.avatar.Contains("http://")) { strTxt.Append(",\"avatar\":\"" + userModel.avatar + "\""); }
                    else { strTxt.Append(",\"avatar\":\"http://" + userModel.avatar + "\""); }
                }
                else
                {
                    strTxt.Append(",\"avatar\":\"http://pic.shicaiquanzi.com" + userModel.avatar + "\"");
                }
            }
            strTxt.Append(",\"company_id\":" + userModel.company_id);
            if (userModel.company_id == 0)
            {
                strTxt.Append(",\"real_name\":\"匿名\"");
                strTxt.Append(",\"company_name\":\"尚未开通\"");
            }
            else
            {
                Model.company coModel = new BLL.company().GetModel(userModel.company_id);
                strTxt.Append(",\"real_name\":\"" + coModel.lianxiren + "\"");
                strTxt.Append(",\"company_name\":\"" + coModel.title + "\"");
            }

            //判断是否有传过来用户名、密码
            if (new BLL.guanzhu().Exists(userModel.id, _cur_userid))
            {
                strTxt.Append(",\"is_guanzhu\":1");
            }
            else
            {
                strTxt.Append(",\"is_guanzhu\":0");
            }
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 通过用户名、密码获取公司资料=============================
        private void get_company_info(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                msg = "{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}";
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                msg = "{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}";
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }
            BLL.company bll = new BLL.company();
            BLL.quanzi quanzibll = new BLL.quanzi();
            Model.company model = bll.GetModel(userModel.company_id);
            StringBuilder strTxt = new StringBuilder();
            if (model != null)
            {
                strTxt.Append("{");
                strTxt.Append("\"status\":1");
                strTxt.Append(",\"id\":" + model.id);
                strTxt.Append(",\"company_name\":\"" + model.title + "\"");
                strTxt.Append(",\"lianxiren\":\"" + model.lianxiren + "\"");
                strTxt.Append(",\"telphone\":\"" + model.telphone + "\"");
                strTxt.Append(",\"mobile\":\"" + model.mobile + "\"");
                strTxt.Append(",\"fax\":\"" + model.fax + "\"");
                //strTxt.Append(",\"website\":\"" + model.website + "\"");
                strTxt.Append(",\"address\":\"" + model.address + "\"");
                strTxt.Append(",\"de_province\":\"" + new BLL.province().GetTitle(model.province_id) + "\"");
                strTxt.Append(",\"de_city\":\"" + new BLL.city().GetTitle(model.city_id) + "\"");
                strTxt.Append(",\"de_district\":\"" + new BLL.district().GetTitle(model.district_id) + "\"");

                strTxt.Append(",\"about\":\"" + Utils.DropHTML(model.about) + "\"");
                strTxt.Append(",\"zuobiao\":\"" + model.zuobiao + "\"");
                strTxt.Append(",\"pro_remark\":\"" + model.pro_remark + "\"");
                ///添加经营范围
                strTxt.Append(",\"isshicai\":\"" + model.Is_jixie + "\"");
                strTxt.Append(",\"businessScope\":\"" + model.businessScope + "\"");

                strTxt.Append(",\"website\":\"" + model.website + "\"");
                ///添加 圈子 ID 和Name
                if (!string.IsNullOrWhiteSpace(model.quanzi_id + "") && model.quanzi_id > 0)
                {
                    strTxt.Append(",\"quanzi_id\":\"" + model.quanzi_id + "\"");
                    strTxt.Append(",\"quanzi_idName\":\"" + quanzibll.GetTitle(model.quanzi_id) + "\"");
                }
                else
                {
                    strTxt.Append(",\"quanzi_id\":\"\"");
                    strTxt.Append(",\"quanzi_idName\":\"\"");
                }

                if (model.logo + "" != "")
                {
                    if (model.logo.Contains("shicaiquanzi"))
                    {
                        if (model.logo.Contains("http://")) { strTxt.Append(",\"logo\":\"" + model.logo + "\""); }
                        else { strTxt.Append(",\"logo\":\"http://" + model.logo + "\""); }
                    }
                    else
                    {
                        strTxt.Append(",\"logo\":\"http://pic.shicaiquanzi.com" + model.logo + "\"");
                    }
                }
                else { strTxt.Append(",\"logo\":\"../image/default_avatar.png\""); }
                //添加user 的头像
                if (userModel.avatar + "" != "")
                {
                    if (userModel.avatar.Contains("shicaiquanzi"))
                    {
                        if (userModel.avatar.Contains("http://")) { strTxt.Append(",\"avatar\":\"" + userModel.avatar + "\""); }
                        else { strTxt.Append(",\"avatar\":\"http://" + userModel.avatar + "\""); }
                    }
                    else
                    {
                        strTxt.Append(",\"avatar\":\"http://pic.shicaiquanzi.com" + userModel.avatar + "\"");
                    }
                }
                else { strTxt.Append(",\"avatar\":\"../image/default_avatar.png\""); }

                //if (model.logo.Contains("shicaiquanzi"))
                //{
                //    strTxt.Append(",\"logo\":\"http://" + model.logo + "\"");
                //}
                //else
                //{
                //    strTxt.Append(",\"logo\":\"http://www.shicaiquanzi.com" + model.logo + "\"");
                //}

                strTxt.Append("}");
            }
            else {
                strTxt.Append("{");
                strTxt.Append("\"status\":0");

                strTxt.Append(",\"id\":0");
                strTxt.Append(",\"company_name\":\"\"");
                strTxt.Append(",\"lianxiren\":\"\"");
                strTxt.Append(",\"telphone\":\"\"");
                strTxt.Append(",\"mobile\":\"\"");
                strTxt.Append(",\"fax\":\"\"");
 
                strTxt.Append(",\"address\":\"\"");
                strTxt.Append(",\"de_province\":\"\"");
                strTxt.Append(",\"de_city\":\"\"");
                strTxt.Append(",\"de_district\":\"\"");

                strTxt.Append(",\"about\":\"\"");
                strTxt.Append(",\"zuobiao\":\"\"");
                strTxt.Append(",\"pro_remark\":\"\"");


                strTxt.Append(",\"website\":\"\"");


                strTxt.Append(",\"msg\":\"温馨提示：您尚未开通企业认证，请填写资料提交认证！\"");
                //添加user 的头像
                if (userModel.avatar + "" != "")
                {
                    if (userModel.avatar.Contains("shicaiquanzi"))
                    {
                        if (userModel.avatar.Contains("http://")) { strTxt.Append(",\"logo\":\"" + userModel.avatar + "\""); }
                        else { strTxt.Append(",\"logo\":\"http://" + userModel.avatar + "\""); }
                    }
                    else
                    {
                        strTxt.Append(",\"logo\":\"http://pic.shicaiquanzi.com" + userModel.avatar + "\"");
                    }
                }
                else { strTxt.Append(",\"logo\":\"../image/default_avatar.png\""); }
                strTxt.Append("}");
                //context.Response.Write("{\"status\":0, \"msg\":\"温馨提示：您尚未开通企业认证，请填写资料提交认证！\"}");
                context.Response.Write(strTxt.ToString());
            }
            //Utils.WriteTextLog("get_company_info", "username:" + _user_name + ",pwd:" + _user_pwd + strTxt + msg, DateTime.Now);
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 我的收藏=============================
        private void collect_list(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            int page_index = DTRequest.GetQueryInt("page_index");
            int page_size = DTRequest.GetQueryInt("page_size");
            int totalcount;

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            StringBuilder strTxt = new StringBuilder();
            if (page_size == 0)
            {
                context.Response.Write("获取失败，传输参数有误！");
                return;
            }

            BLL.collection bll = new BLL.collection();
            DataSet ds = bll.GetList(page_size, page_index, "user_id=" + userModel.id, "id desc", out totalcount);
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"channel_id\":" + dr["channel_id"]);
                    string channel_name = string.Empty;
                    switch (Convert.ToInt32(dr["channel_id"]))
                    {
                        case 1:
                            channel_name = "求购";
                            break;
                        case 2:
                            channel_name = "供应";
                            break;
                    }
                    strTxt.Append(",\"channel_name\":\"" + channel_name + "\"");
                    strTxt.Append(",\"article_id\":" + dr["article_id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr["add_time"])) + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                context.Response.Write("{\"status\":2}");
                return;
            }
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 添加收藏=============================
        private void collect_add(HttpContext context)
        {
            //检查用户是否登录
            string user_name = DTRequest.GetFormString("txtUserName");
            string user_pwd = DTRequest.GetFormString("txtPassword");
            int _channel_id = DTRequest.GetFormInt("channel_id");
            int _article_id = DTRequest.GetFormInt("article_id");

            if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_pwd))
            {
                Utils.WriteTextLog("collect_add", "username:" + user_name + ",pwd:" + user_pwd + "您的登录信息有误，请退出系统后重新登录！", DateTime.Now);
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }
            Model.users userModel = new BLL.users().GetModel(user_name, user_pwd, 0, 1, true);
            if (userModel == null)
            {
                Utils.WriteTextLog("collect_add", "username:" + user_name + ",pwd:" + user_pwd + "您的登录信息有误，请退出系统后重新登录！", DateTime.Now);
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }

            BLL.collection bll = new BLL.collection();
            //先判断是否有收藏过bll.Exists(_channel_id, _article_id, userModel.id)
            DataSet dscollectionlist = bll.GetIdByChannelidarticleiduserid(_channel_id, _article_id, userModel.id);
            if (dscollectionlist.Tables[0].Rows.Count>0)
            {
                //收藏过的 在这里接着写  删除2019-01-06
                for (int i = 0; i < dscollectionlist.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = dscollectionlist.Tables[0].Rows[i];
                    bll.Delete(int.Parse(dr["id"] + ""));
                }
                context.Response.Write("{\"status\":2, \"msg\":\"已取消收藏！\"}");
                //context.Response.Write("{\"status\": 0, \"msg\": \"已经收藏过了！\"}");
                return;
            }
            //获取title
            string _title = string.Empty;
            switch (_channel_id)
            {
                case 1:
                    _title = new BLL.qiugou().GetTitle(_article_id);
                    break;
                case 2:
                    _title = new BLL.gongying().GetTitle(_article_id);
                    break;
                case 3:
                    _title = new BLL.product().GetTitle(_article_id);
                    break;
                case 4:
                    _title = new BLL.xinxi().GetRemark(_article_id);
                    break;
            }

            Model.collection model = new Model.collection();
            model.title = _title;
            model.channel_id = _channel_id;
            model.article_id = _article_id;
            model.add_time = DateTime.Now;
            model.user_id = userModel.id;

            if (bll.Add(model) > 0)
            {
                context.Response.Write("{\"status\": 1, \"msg\": \"收藏成功！\"}");
                return;
            }
            context.Response.Write("{\"status\": 0, \"msg\": \"保存过程中发生错误！\"}");
            return;
          
        }
        #endregion

        #region 删除收藏信息=============================
        private void collect_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.collection bll = new BLL.collection();
            Model.collection model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 开通企业店铺===========================
        private void company_add(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");
            try
            {
                if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
                {
                    msg = "{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}";
                    context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                    return;
                }

                Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
                if (userModel == null)
                {
                    msg = "{\"status\":0, \"msg\":\"错误提示：用户名或密码错误\"}";
                    context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                    return;
                }
                //判断店铺是否开通
                if (userModel.company_id > 0)
                {
                    msg = "{\"status\":0, \"msg\":\"抱歉：您已开通企业店铺，不能重复开通！\"}";
                    context.Response.Write("{\"status\":0, \"msg\":\"抱歉：您已开通企业店铺，不能重复开通！\"}");
                    return;
                }

                StringBuilder strTxt = new StringBuilder();
                BLL.company bll = new BLL.company();
                Model.company model = new Model.company();

                //获取传值
                string _company_name = DTRequest.GetFormString("txtCompanyName");
                string _lianxiren = DTRequest.GetFormString("txtLianxiren");
                string _telephone = DTRequest.GetFormString("txtTelephone");
                string _mobile = DTRequest.GetFormString("txtMobile");
                string _fax = DTRequest.GetFormString("txtFax");
                string _address = DTRequest.GetFormString("txtAddress");

                if (string.IsNullOrEmpty(_company_name))
                {
                    context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入公司名称！\"}");
                    return;
                }
                if (string.IsNullOrEmpty(_lianxiren))
                {
                    context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入联系人！\"}");
                    return;
                }
                if (string.IsNullOrEmpty(_mobile))
                {
                    context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入手机号！\"}");
                    return;
                }
                if (string.IsNullOrEmpty(_address))
                {
                    context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入公司地址！\"}");
                    return;
                }
                //先上传图片
                HttpPostedFile upFile = context.Request.Files["file"];
                if (upFile != null)
                {
                    string logo_file = FileSave(context, upFile, true);//20190415水印
                    model.logo = logo_file;
                }
                model.user_id = userModel.id;
                model.title = _company_name;
                model.lianxiren = _lianxiren;
                model.telphone = _telephone;
                model.mobile = _mobile;
                model.fax = _fax;
                model.address = _address;
                model.status = 1;
                model.add_time = DateTime.Now;

                int result = bll.Add(model);

                if (result > 0)
                {
                    msg = "{\"status\": 1, \"msg\": \"恭喜您，店铺开通成功，请继续完善店铺资料！\"}";
                    context.Response.Write("{\"status\": 1, \"msg\": \"恭喜您，店铺开通成功，请继续完善店铺资料！\"}");
                    //更新开通店铺状态
                    new BLL.users().UpdateField(userModel.id, "company_id=" + result);
                    return;
                }
                //Utils.WriteTextLog("company_add", "username:" + _user_name + ",pwd:" + _user_pwd + strTxt + msg, DateTime.Now);
            }
            catch(Exception ex) {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
                Utils.WriteTextLog("company_add", "username:" + _user_name + ",pwd:" + _user_pwd + ex.Message + ex.StackTrace, DateTime.Now);
            }
            
            return;
        }
        #endregion

        #region 编辑店铺基本资料===========================
        private void company_edit(HttpContext context)
        {
            string msg = "";
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");
            try
            {
                if (_user_name == "嘉祥鑫灿石业有限公司") {
                    context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                    return;
                }
                if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
                {
                    context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                    return;
                }

                Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
                if (userModel == null)
                {
                    context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                    return;
                }
                //判断是否开通过店铺
                if (userModel.company_id == 0)
                {
                    //context.Response.Write("{\"status\":0, \"msg\":\"抱歉，您尚未开通店铺！\"}");
                    //return;
                    //修改逻辑 如果 未开通店铺 先开通店铺
                    company_add(context);
                }
                else
                {

                    //获取传值
                    string _companyname = DTRequest.GetFormString("txtCompanyName");
                    string _lianxiren = DTRequest.GetFormString("txtLianxiren");
                    string _telephone = DTRequest.GetFormString("txtTelephone");
                    string _mobile = DTRequest.GetFormString("txtMobile");
                    string _fax = DTRequest.GetFormString("txtFax");
                    string _address = DTRequest.GetFormString("txtAddress");
                    string _product = DTRequest.GetFormString("txtProduct");
                    string _remark = DTRequest.GetFormString("txtRemark");

                    string _provnce = DTRequest.GetFormString("txtProvnce");
                    string _city = DTRequest.GetFormString("txtCity");
                    string _district = DTRequest.GetFormString("txtDistrict");
                    string is_shicai = DTRequest.GetFormString("is_shicai");
                    string _businesscode = DTRequest.GetFormString("txtbusinesscode");
                    string _website = DTRequest.GetFormString("txtwebsite");
                    string _quanzi_id = DTRequest.GetFormString("ddlquanziID");
                    msg += "_companyname:"+ _companyname+"\r\n";
                    msg += "_lianxiren:" + _lianxiren + "\r\n";
                    msg += "_telephone:" + _telephone + "\r\n";
                    msg += "_mobile:" + _mobile + "\r\n";
                    msg += "_fax:" + _fax + "\r\n";
                    msg += "_address:" + _address + "\r\n";
                    msg += "_product:" + _product + "\r\n";
                    msg += "_remark:" + _remark + "\r\n";
                    msg += "_businesscode:" + _businesscode + "\r\n";
                    msg += "_website:" + _website + "\r\n";
                    msg += "_quanzi_id:" + _quanzi_id + "\r\n";
                    if (string.IsNullOrEmpty(_lianxiren))
                    {
                        context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入联系人！\"}");
                        return;
                    }
                    if (string.IsNullOrEmpty(_mobile))
                    {
                        context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入手机号！\"}");
                        return;
                    }
                    if (string.IsNullOrEmpty(_address))
                    {
                        context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入公司地址！\"}");
                        return;
                    }

                    BLL.company bll = new BLL.company();
                    Model.company model = bll.GetModel(userModel.company_id);

                    model.title = _companyname;
                    model.lianxiren = _lianxiren;
                    model.telphone = _telephone;
                    model.mobile = _mobile;
                    model.fax = _fax;
                    model.address = _address;
                    model.pro_remark = _product;
                    model.about = _remark;
                    model.website = _website;
                    
                    if (Utils.isNumber(_provnce) && int.Parse(_provnce) > 0)
                    {
                        model.province_id = int.Parse(_provnce);
                    }
                    if (Utils.isNumber(_city) && int.Parse(_city) > 0)
                    {
                        model.city_id = int.Parse(_city);
                    }
                    if (Utils.isNumber(_district) && int.Parse(_district) > 0)
                    {
                        model.district_id = int.Parse(_district);
                    }
                    if (Utils.isNumber(is_shicai))
                    {
                        model.Is_jixie = int.Parse(is_shicai);
                    }
                    else { model.Is_jixie =0; }

                    if (Utils.isNumber(_quanzi_id) && int.Parse(_quanzi_id) > 0)
                    {
                        model.quanzi_id = int.Parse(_quanzi_id);
                    }

                    model.businessScope = _businesscode;
                    if (userModel.avatar + "" != "") { model.logo = userModel.avatar; }
                    bll.Update(model);
                    Utils.WriteTextLog("company_edit", "username:" + _user_name + ",pwd:" + _user_pwd + msg, DateTime.Now);
                    //new BLL.users().UpdateField(userModel.id, "user_name='" + _companyname + "'");
                    context.Response.Write("{\"status\":1, \"msg\":\"店铺资料已修改成功！\"}");
                    return;
                }
            }
            catch (Exception ex) {
                context.Response.Write("{\"status\":0, \"msg\":\"保存遇到错误，请稍后重试！\"}");
                Utils.WriteTextLog("company_edit", "username:" + _user_name + ",pwd:" + _user_pwd  + ex.Message+ex.StackTrace, DateTime.Now);
            }
            
        }
        #endregion

        #region 编辑公司简介===========================
        private void company_about_edit(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }
            //判断是否开通过店铺
            if (userModel.company_id == 0)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"抱歉，您尚未开通店铺！\"}");
                return;
            }

            //获取传值
            string _remark = DTRequest.GetFormString("txtRemark");

            if (string.IsNullOrEmpty(_remark))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入公司简介详细内容！\"}");
                return;
            }

            BLL.company bll = new BLL.company();
            Model.company model = bll.GetModel(userModel.company_id);

            model.about = _remark;
            
            bll.Update(model);
            context.Response.Write("{\"status\":1, \"msg\":\"店铺资料已修改成功！\"}");
            return;
        }
        #endregion

        #region 编辑公司经纬度 坐标===========================
        private void company_edit_zuobiao(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }
            //判断是否开通过店铺
            if (userModel.company_id == 0)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"抱歉，您尚未开通店铺！\"}");
                return;
            }

            //获取传值
            string _zuobiao = DTRequest.GetFormString("txtzuobiao");

            if (string.IsNullOrEmpty(_zuobiao))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，为获取到经纬度信息！\"}");
                return;
            }

            BLL.company bll = new BLL.company();
            Model.company model = bll.GetModel(userModel.company_id);

            model.zuobiao = _zuobiao;

            bll.Update(model);
            context.Response.Write("{\"status\":1, \"msg\":\"店铺资料已修改成功！\"}");
            return;
        }
        #endregion

        #region 编辑店铺LOGO===========================
        private void company_logo_edit(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }
            BLL.users userbll = new BLL.users();
            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }


            //string msg = "";
            //先上传图片
            HttpPostedFile upFile = context.Request.Files["file"];
            if (upFile != null)
            {
                string logo_file = FileSave(context, upFile, true);//20190415 水印
                userModel.avatar = logo_file;
                userbll.Update(userModel);
                //msg += ",userModel.avatar:" + userModel.avatar;
                //判断是否开通过店铺
                if (userModel.company_id > 0)
                {
                    BLL.company bll = new BLL.company();
                    Model.company model = bll.GetModel(userModel.company_id);
                    model.logo = logo_file;
                    bll.Update(model);
                    //msg += ",company_logo:" + model.logo;
                }
                

            }
           
            //Utils.WriteTextLog("company_logo_edit", "username:" + _user_name + ",pwd:" + _user_pwd + "上传LOGO！"+ msg, DateTime.Now);
            context.Response.Write("{\"status\":1, \"msg\":\"上传店铺LOGO成功！\"}");
            return;
        }
        #endregion

        #region 获取产品分类===========================
        private void get_product_category(HttpContext context)
        {
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取供应信息
            BLL.product_category bll = new BLL.product_category();
            DataSet ds = bll.GetList(0, "", "sort_id asc,id asc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"category_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 提交产品信息===========================
        private void product_add(HttpContext context)
        {
            //检查用户是否登录
            string user_name = DTRequest.GetFormString("txtUserName");
            string user_pwd = DTRequest.GetFormString("txtPassword");
            if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_pwd))
            {
                Utils.WriteTextLog("product_add", "username:" + user_name + ",pwd:" + user_pwd + "您的登录信息有误，请退出系统后重新登录！", DateTime.Now);
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }
            Model.users userModel = new BLL.users().GetModel(user_name, user_pwd, 0, 1, true);
            if (userModel == null)
            {
                Utils.WriteTextLog("product_add", "username:" + user_name + ",pwd:" + user_pwd+ "您的登录信息有误，请退出系统后重新登录！", DateTime.Now);
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }

            BLL.product bll = new BLL.product();
            Model.product model = new Model.product();

            string _title = DTRequest.GetFormString("txtTitle");
            int _category_id = DTRequest.GetFormInt("slCategoryID", 0);
            int _price = DTRequest.GetFormInt("txtPrice", 0);
            string _unit = DTRequest.GetFormString("slUnit");
            string _remark = DTRequest.GetFormString("txtRemark");

            if (string.IsNullOrEmpty(_title))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入标题！\"}");
                return;
            }

            if (string.IsNullOrEmpty(_remark))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入内容！\"}");
                return;
            }

            model.category_id = _category_id;
            model.title = _title;
            model.price = _price;
            model.unit = _unit;
            model.content = _remark;
            model.company_id = userModel.company_id;
            model.status = 1;
            model.hits = 0;
            model.add_time = DateTime.Now;
            model.user_id = userModel.id;

            #region 保存相册====================
            HttpFileCollection files = context.Request.Files;
            if (files.Count > 0)
            {
                List<Model.common_albums> ls = new List<Model.common_albums>();
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFile myFile = files[i];
                    //string filePath = FileSave(context, myFile, false);
                    //获取文件信息
                    string fileName = myFile.FileName;
                    byte[] byteData = FileHelper.ConvertStreamToByteBuffer(myFile.InputStream); //获取文件流
                    //开始上传
                    string remsg = new UpLoad().FileSaveAs(byteData, fileName, true, true);//20190415  水印
                    Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(remsg);

                    string thumb_path = dic["thumb"].ToString(); //取得上传后的路径
                    string original_path = dic["path"].ToString();

                    ls.Add(new Model.common_albums { channel_id = 3, original_path = original_path, thumb_path = thumb_path });
                    //设置默认图片
                    if (i == 0)
                    {
                        model.img_url = thumb_path;
                    }
                }
                model.albums = ls;
            }
            else
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"请至少上传一张图片！\"}");
                return;
            }
            #endregion

            if (bll.Add(model) > 0)
            {
                context.Response.Write("{\"status\": 1, \"msg\": \"恭喜您，产品提交成功！\"}");
                return;
            }
            context.Response.Write("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
            return;
        }
        #endregion

        #region 提交相册===========================
        private void xiangce_add(HttpContext context)
        {
            //检查用户是否登录
            string user_name = DTRequest.GetFormString("txtUserName");
            string user_pwd = DTRequest.GetFormString("txtPassword");
            if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_pwd))
            {
                Utils.WriteTextLog("xiangce_add", "username:" + user_name + ",pwd:" + user_pwd + "您的登录信息有误，请退出系统后重新登录！", DateTime.Now);
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }
            Model.users userModel = new BLL.users().GetModel(user_name, user_pwd, 0, 1, true);
            if (userModel == null)
            {
                Utils.WriteTextLog("xiangce_add", "username:" + user_name + ",pwd:" + user_pwd + "您的登录信息有误，请退出系统后重新登录！", DateTime.Now);
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }

            BLL.xiangce bll = new BLL.xiangce();
            Model.xiangce model = new Model.xiangce();

            string _title = DTRequest.GetFormString("txtTitle");
            string _remark = DTRequest.GetFormString("txtRemark");

            if (string.IsNullOrEmpty(_title))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入标题！\"}");
                return;
            }

            if (string.IsNullOrEmpty(_remark))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入内容！\"}");
                return;
            }

            model.title = _title;
            model.content = _remark;
            model.company_id = userModel.company_id;
            model.add_time = DateTime.Now;
            model.user_id = userModel.id;

            #region 保存相册====================
            HttpFileCollection files = context.Request.Files;
            if (files.Count > 0)
            {
                List<Model.common_albums> ls = new List<Model.common_albums>();
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFile myFile = files[i];
                    //string filePath = FileSave(context, myFile, false);
                    //获取文件信息
                    string fileName = myFile.FileName;
                    byte[] byteData = FileHelper.ConvertStreamToByteBuffer(myFile.InputStream); //获取文件流
                    //开始上传
                    string remsg = new UpLoad().FileSaveAs(byteData, fileName, true, true);//相册保存水印 20190414
                    Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(remsg);

                    string thumb_path = dic["thumb"].ToString(); //取得上传后的路径
                    string original_path = dic["path"].ToString();

                    ls.Add(new Model.common_albums { channel_id = 6, original_path = original_path, thumb_path = thumb_path });
                    //设置默认图片
                    if (i == 0)
                    {
                        model.img_url = thumb_path;
                    }
                }
                model.albums = ls;
            }
            #endregion

            if (bll.Add(model) > 0)
            {
                context.Response.Write("{\"status\": 1, \"msg\": \"恭喜您，图片添加成功！\"}");
                return;
            }
            context.Response.Write("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
            return;
        }
        #endregion

        #region 删除相册=============================
        private void xiangce_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.xiangce bll = new BLL.xiangce();
            Model.xiangce model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete(6, article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 相册置顶=============================
        private void xiangce_toTop(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("操作失败，传输参数有误！");
                return;
            }

            BLL.xiangce bll = new BLL.xiangce();
            Model.xiangce model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("操作失败，您不能操作别人的信息！");
                return;
            }
            bll.UpdateField( article_id, " add_time=getdate()");
            context.Response.Write("{\"status\":1, \"msg\":\"置顶成功！\"}");
            return;
        }
        #endregion

        #region 产品置顶=============================
        private void product_toTop(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("操作失败，传输参数有误！");
                return;
            }

            BLL.product bll = new BLL.product();
            Model.product model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.user_id != userModel.id)
            {
                context.Response.Write("操作失败，您不能操作别人的信息！");
                return;
            }
            bll.UpdateField(article_id, " add_time=getdate()");
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion

        #region 提交banner===========================
        private void banner_add(HttpContext context)
        {
            //检查用户是否登录
            string user_name = DTRequest.GetFormString("txtUserName");
            string user_pwd = DTRequest.GetFormString("txtPassword");
            if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_pwd))
            {
                Utils.WriteTextLog("banner_add", "username:" + user_name + ",pwd:" + user_pwd + "您的登录信息有误，请退出系统后重新登录！", DateTime.Now);
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }
            Model.users userModel = new BLL.users().GetModel(user_name, user_pwd, 0, 1, true);
            if (userModel == null)
            {
                Utils.WriteTextLog("banner_add", "username:" + user_name + ",pwd:" + user_pwd + "您的登录信息有误，请退出系统后重新登录！", DateTime.Now);
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }
            if (userModel.company_id ==0)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"尚未开通企业店铺，无法添加图片！\"}");
                return;
            }

            BLL.company_albums bll = new BLL.company_albums();






            #region 保存相册====================
            bool successcount = true;
            string msg = "对不起，保存过程中发生错误！";
            HttpFileCollection files = context.Request.Files;
            if (files.Count > 0)
            {
               
                for (int i = 0; i < files.Count; i++)
                {
                    ///判断只能保存3张
                    int count = bll.GetCount(" company_id =" + userModel.company_id);
                    //Utils.WriteTextLog("banner_add", "username:" + user_name + ",pwd:" + user_pwd + "当前已有记录总数！"+ count, DateTime.Now);
                    if (count >= 3)
                    {
                        successcount = false;
                        msg = "该模块最多只能保存3张图片!";
                        //context.Response.Write("{\"status\": 1, \"msg\": \"该模块最多只能保存3张图片！\"}");
                        //return;
                    }
                    else
                    {
                        Model.company_albums model = new Model.company_albums();
                        HttpPostedFile myFile = files[i];
                        //string filePath = FileSave(context, myFile, false);
                        //获取文件信息
                        string fileName = myFile.FileName;
                        byte[] byteData = FileHelper.ConvertStreamToByteBuffer(myFile.InputStream); //获取文件流
                                                                                                    //开始上传
                        string remsg = new UpLoad().FileSaveAs(byteData, fileName, true, true);//20190415 水印
                        Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(remsg);

                        string thumb_path = dic["thumb"].ToString(); //取得上传后的路径
                        string original_path = dic["path"].ToString();

                        model.company_id = userModel.company_id;
                        model.typeid = 1;
                        model.thumb_path = thumb_path;
                        model.original_path = original_path;
                        model.add_time = DateTime.Now;
                        if (bll.Add(model) > 0)
                        {
                            successcount = true;
                        }
                        else
                        {
                            successcount=false;
                        }
                    }
                }
            }
            #endregion


            if (successcount)
            {
                context.Response.Write("{\"status\": 1, \"msg\": \"恭喜您，图片添加成功！\"}");
                return;
            }
            else
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"" + msg + "\"}");
            }
            return;
        }
        #endregion

        #region 删除banner=============================
        private void banner_delete(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            int article_id = DTRequest.GetInt("article_id", 0);
            if (article_id == 0)
            {
                context.Response.Write("删除失败，传输参数有误！");
                return;
            }

            BLL.company_albums bll = new BLL.company_albums();
            Model.company_albums model = bll.GetModel(article_id);
            //判断是不是自己发布的内容
            if (model.company_id != userModel.company_id)
            {
                context.Response.Write("删除失败，您不能删除别人的信息！");
                return;
            }
            bll.Delete( article_id);
            context.Response.Write("{\"status\":1, \"msg\":\"删除成功！\"}");
            return;
        }
        #endregion


        #region 获取用户组别信息 升级会员使用=============================
        private void get_userGroups(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");
            /// Demon 添加 20200228 手机系统类型  
            /// ios
            /// android       
            /// win             //Windows系统   
            /// wp              //Windows Phone系统
            string _systemType = DTRequest.GetString("systemType");
            BLL.company combll = new BLL.company();
            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();

            strTxt.Append("{");
            //获取会员级别信息
            BLL.user_groups bll = new BLL.user_groups();
            DataSet ds = bll.GetList(0, " price>0", "grade asc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"groups_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"grade\":" + dr["grade"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"price\":\"" + dr["price"] + "\"");
                    strTxt.Append(",\"is_lock\":\"" + dr["is_lock"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }
        #endregion


        #region Demon 添加 获取@我的消息=============================
        private void get_xinxicomment_at(HttpContext context)
        {
            string _user_name = DTRequest.GetString("txtUserName");
            string _user_pwd = DTRequest.GetString("txtPassword");

            //BLL.company combll = new BLL.company();
            if (string.IsNullOrEmpty(_user_name) || string.IsNullOrEmpty(_user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！！"+ _user_name+","+ _user_pwd + "\"}");
                return;
            }

            Model.users userModel = new BLL.users().GetModel(_user_name, _user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：用户名或密码错误！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();
            //Model.company model = new Model.company();
            if (userModel.company_id > 0)
            {
                strTxt.Append("{");
                //获取会员级别信息
                BLL.xinxi_comment_at bll = new BLL.xinxi_comment_at();
                DataSet ds = bll.GetList(0, " user_id=" + userModel.company_id, "add_time desc");
                //如果记录存在
                if (ds.Tables[0].Rows.Count > 0)
                {
                    strTxt.Append("\"xinxicomment_at_list\":[");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        DataRow dr = ds.Tables[0].Rows[i];
                        strTxt.Append("{");
                        strTxt.Append("\"article_id\":" + dr["article_id"]);
                        string article_title = new BLL.xinxi().GetContent(int.Parse(dr["article_id"].ToString()));
                        string article_con = Utils.DropHTML(article_title);
                        if (article_con.Length > 10) { article_con = article_con.Substring(0,20) + "..."; }
                        strTxt.Append(",\"article_title\":\"" + article_con + "\"");
                        strTxt.Append(",\"comment_id\":\"" + dr["comment_id"] + "\"");
                        string comment_remark = new BLL.xinxi_comment().GetRemark(int.Parse(dr["comment_id"].ToString()));
                        strTxt.Append(",\"comment_remark\":\"" + comment_remark + "\"");
                        int comment_user_id = new BLL.xinxi_comment().GetCommentUser_id(int.Parse(dr["comment_id"].ToString()));
                        strTxt.Append(",\"comment_user_id\":\"" + comment_user_id + "\"");
                        strTxt.Append(",\"comment_user_name\":\"" + new BLL.users().GetUserName(comment_user_id)+ "\"");
                        strTxt.Append(",\"user_id\":\"" + dr["user_id"] + "\"");
                        strTxt.Append(",\"add_time\":\"" + dr["add_time"] + "\"");
                        strTxt.Append(",\"is_read\":\"" + dr["is_read"] + "\"");
                        strTxt.Append("}");
                        //是否加逗号
                        if (i < ds.Tables[0].Rows.Count - 1)
                        {
                            strTxt.Append(",");
                        }
                    }
                    strTxt.Append("]");
                }
                strTxt.Append("}");
            }
            else {
                context.Response.Write("{\"status\":0, \"msg\":\"错误提示：您尚未开通企业店铺！\"}");
                return;
            }
           
           
           
            context.Response.Write(strTxt.ToString());
        }
        #endregion
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}